<!DOCTYPE html>
<html class="ui-page-login">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title></title>
    <script src="__PUBLIC__/js/jquery.min.js"></script>
    <script src="__PUBLIC__/home/plugins/layer/layer.js"></script>
    <script src="__PUBLIC__/mui/js/mui.min.js"></script>
    <script src="__PUBLIC__/js/angular.js"></script>
    <script src="__PUBLIC__/common.js"></script>
    <link rel="stylesheet" href="__PUBLIC__/mui/css/mui.css"/>
    <link rel="stylesheet" href="__PUBLIC__/js/nice-validator-0.10.11/dist/jquery.validator.css"/>
    <script src="__PUBLIC__/js/nice-validator-0.10.11/dist/jquery.validator.js"></script>
    <script src="__PUBLIC__/js/nice-validator-0.10.11/dist/local/zh-CN.js"></script>
    <style>
        .btn-width {
            margin-right: 1em;
            text-align: center;
            padding: 5px 10px !important;
            height: 30px;
            margin-top: 5px;
            border-radius: 0;
            width: 20% !important;
        }

        #member-login {
            display: none;
        }

        .area {
            margin: 20px auto 0px auto;
        }

        .mui-input-group {
            margin-top: 10px;
        }

        .mui-input-group:first-child {
            margin-top: 20px;
        }

        .mui-input-group label {
            width: 50%;
            font-size: 15px;
            color: black;

        }

        .mui-input-row label ~ input,
        .mui-input-row label ~ select,
        .mui-input-row label ~ textarea {
            width: 70%;
        }

        .mui-checkbox input[type=checkbox],
        .mui-radio input[type=radio] {
            top: 6px;
        }

        .mui-content-padded {
            margin-top: 25px;
        }

        .mui-btn {
            padding: 10px;
        }

        .link-area {
            display: block;
            margin-top: 25px;
            text-align: center;
        }

        .spliter {
            color: #bbb;
            padding: 0px 8px;
        }

        .oauth-area {
            position: absolute;
            bottom: 20px;
            left: 0px;
            text-align: center;
            width: 100%;
            padding: 0px;
            margin: 0px;
        }

        .oauth-area .oauth-btn {
            display: inline-block;
            width: 50px;
            height: 50px;
            background-size: 30px 30px;
            background-position: center center;
            background-repeat: no-repeat;
            margin: 0px 20px;
            /*-webkit-filter: grayscale(100%); */
            border: solid 1px #ddd;
            border-radius: 25px;
        }

        .oauth-area .oauth-btn:active {
            border: solid 1px #aaa;
        }

        .oauth-area .oauth-btn.disabled {
            background-color: #ddd;
        }

        .login-active {
            background: #f3363a;
        }

        .content {
            width: 50%;
            float: right;
            line-height: 40px;
            height: 40px;
            font-size: 16px;
            text-align: right;
            padding-right: 1em;

        }

        .go-item {
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            padding: 0;
            margin: 0;
            background: white;
            height: 60px;
            text-align: center;

        }

        #user-login .mui-input-row .time {
            width: 65%;
            color: black;
        }

        #user-login .mui-input-row .status {
            width: 35%;
            font-size: 14px;
            font-weight: bold;
            font-family: "Microsoft YaHei UI Light";

        }

        .mui-input-group .mui-input-row:after {
            left: 0;
        }

        .mui-input-group .mui-input-row:nth-child(1):after {
            background: none;
        }

        .mui-input-group .mui-input-row:last-child:after {
            background: none;
        }

        #user-login .mui-input-group {
            margin-top: 0;
        }

        #withdraw {
            color: white;
            font-size: 16px;
            line-height: 44px;
            margin: 0;
            padding: 0;
            height: 44px;
        }

        #user-login .mui-input-group {
            background: #f6f6f6
        }

        .mui-segmented-control .mui-control-item.mui-active {
            color: #ff6769;
            background: #fff;
        }

        .mui-segmented-control .mui-control-item {
            border-left: 1px solid #EDEDED;
            background: #fff;
        }

        .mui-segmented-control .mui-control-item {
            color: #666666;
        }

        html {
            height: 85%;
        }

        body {
            height: 100%;
        }
    </style>

</head>
<body ng-app="myApp" ng-controller="Ctrl" ng-cloak>
<header class="mui-bar mui-bar-nav" style="background:#f3363a;">
    <a class="mui-icon mui-icon-left-nav mui-pull-left" style="color: white" href="/index.php/Home/agen/item"></a>
    <h1 class="mui-title login-item" style="color: white">订单管理</h1>
</header>


<div class="mui-content" ng-show="kdflg==0">
    <div style="padding: 4px 2px;background: #ffffff;">
        <div id="segmentedControl" class="mui-segmented-control">
            <a id="st0" class="mui-control-item mui-active">
                全部
            </a>
            <a id="st2" class="mui-control-item">
                未发货
            </a>
            <a id="st3" class="mui-control-item">
                已发货
            </a>
            <a id="st4" class="mui-control-item">
                已完成
            </a>
        </div>
    </div>
    <div class="mui-input-group" style="margin-top: 3px" ng-repeat="order in message">
        <div class="mui-input-row" style="background: #F0F0F0;">
            <label class="time" style="width: 65%">{{order.createtime}}</label>
            <div class="content  " style="color: #f2373b;width: 35%;">
                <div ng-show="order.status == 2">
                    未发货
                </div>
                <div ng-show="order.status == 3">
                    已发货
                </div>
                <div ng-show="order.status == 4">
                    已完成
                </div>
            </div>
        </div>

        <div class="mui-input-row" style="background:white">
            <label class="time" style="font-size: 12px; width: 58%;">订单号:{{order.sn}}</label>
            <div class="content  " style="color: #f2373b;width: 42%;">
                总额：<span style="color:#ff6769;font-size: 15px;">￥{{order.total}}</span>
            </div>
        </div>
        <div class="mui-input-row">
            <label>代理 </label>
            <div class="content">
                {{order.account}}
            </div>
        </div>

        <div class="mui-input-row">
            <label>商品</label>
            <div class="content">
                {{order.name}}
            </div>
        </div>
        <div class="mui-input-row">
            <label>数量</label>
            <div class="content">
                <span ng-hide="order.num*1 >= order.boxnum*1">{{order.num}}盒</span>
                <span ng-show="order.num*1 >= order.boxnum*1">{{floor(order.num/order.boxnum)}}箱{{order.num%order.boxnum}}盒</span>
            </div>
        </div>
        <div class="mui-input-row" style="background:white">
            <button type="button" class="mui-btn mui-btn-danger mui-btn-outlined btn-width" style="float: left;margin-left: 10px"
                    ng-click="orderdetail(order.id)">详情
            </button>

            <div ng-show="order.status == 2">
                <button type="button" class="mui-btn mui-btn-danger mui-btn-outlined btn-width"
                        ng-show="order.num/order.boxnum>=1" ng-click="saoma(order.id)">扫码发货
                </button>
                <button type="button" class="mui-btn mui-btn-danger mui-btn-outlined btn-width" ng-click="send(order.id)">
                    确认发货
                </button>
                <button type="button" class="mui-btn mui-btn-outlined btn-width" ng-click="upto(order.id,2)"
                        ng-show="order.num/order.boxnum>order.flownum">流转上级
                </button>
                <!--<button type="button" class="mui-btn mui-btn-outlined btn-width" ng-click="upto(order.id,2)" >流转上级</button>-->
            </div>
            <div ng-show="order.status == 3">
                <button type="button" class="mui-btn mui-btn-danger mui-btn-outlined btn-width"
                        ng-click="logistics(order.logistics,order.logisticscom,order.id)">查看物流
                </button>
            </div>
            <div ng-show="order.status == 4">
                <button type="button" class="mui-btn mui-btn-danger mui-btn-outlined btn-width" disabled>已完成</button>
            </div>
        </div>
    </div>

</div>
<div class="mui-content" style="margin-bottom: 50px;height: 100%;" ng-show="kdflg==1">
    <ul class="mui-table-view" style="margin-bottom: 2px">
        <li class="mui-table-view-cell mui-media">
            <div class="mui-content" style="background: white;width: 70%;float: left">
                <button class="mui-btn  mui-btn-danger mui-pull-right" style="width: 50%;" ng-click="logisticsback()">
                    返回
                </button>
            </div>
        </li>
    </ul>
    <li class="mui-table-view-cell">
        <a>收货人姓名<span class="mui-pull-right">{{lgsts.receivename}}</span></a>
    </li>
    <li class="mui-table-view-cell">
        <a>收货人电话<span class="mui-pull-right">{{lgsts.phone}}</span></a>
    </li>
    <li class="mui-table-view-cell">
        <a>收货人地址<span class="mui-pull-right">{{lgsts.namepath}}</span></a>
    </li>
    <li class="mui-table-view-cell">
        <a>收货人详细地址<span class="mui-pull-right">{{lgsts.address}}</span></a>
    </li>
    <div style="height: 4px;background:#efeff4; "></div>
    <iframe src="" frameborder="0" id="kdshow" name="kdshow" style="width: 100%;height: 100%;"></iframe>
</div>
<include file="./Application/Home/View/pub/agentfoot.html" name="i"/>
<script>
    var app = angular.module("myApp", []);

    app.controller('Ctrl', function ($scope, $http) {
        document.getElementById('st0').addEventListener('tap', function () {
            $scope.getbystatus(0);
        });
        document.getElementById('st2').addEventListener('tap', function () {
            $scope.getbystatus(2);
        });
        document.getElementById('st3').addEventListener('tap', function () {
            $scope.getbystatus(3);
        });
        document.getElementById('st4').addEventListener('tap', function () {
            $scope.getbystatus(4);
        });

        $scope.floor = function (number) {
            return Math.floor(number);
        };
        // 查看物流flg
        $scope.kdflg = 0

        var flg = getUrlParam('flg');
        if (flg == 2) {
            $scope.status = 2;
            $('#st0').removeClass("mui-active");
            $('#st2').addClass("mui-active");
        } else if (flg == 3) {
            $scope.status = 3;
            $('#st0').removeClass("mui-active");
            $('#st3').addClass("mui-active");
        } else if (flg == 4) {
            $scope.status = 4;
            $('#st0').removeClass("mui-active");
            $('#st4').addClass("mui-active");
        }
        // 当前页数
        $scope.currentPage = 0;
        // 加载完毕标志
        $scope.endflg = 0;
        // 防止重复加载
        $scope.busy = false;
        // 存放数据
        $scope.message = [];
        // 请求数据方法
        $scope.loadMore = function () {
            //console.log($scope.currentPage)
            if ($scope.endflg == 0) {
                if ($scope.busy) {
                    return false;
                }
                $scope.busy = true;
                $http({
                    method: 'POST',
                    data: $scope,
                    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                    transformRequest: function (obj) {
                        var str = [];
                        for (var p in obj) {
                            str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                        }
                        return str.join("&");
                    },
                    url: "/index.php/Home/AgentOnlineorder/getalltoagenorder"
                }).then(function successCallback(response) {
                    //console.log(response.data)
                    $scope.busy = false;
                    if (response.data.data != '' && response.data.data != null) {
                        if ($scope.currentPage > 0) {
                            layer.msg("正在加载...", {time: 500});
                        }
                    } else {
                        layer.msg("已加载完毕", {time: 500});
                        $scope.endflg = 1;
                        return false;
                    }
                    $scope.currentPage++;
                    if (response.data.code == -1) {
                        layer.msg(response.data.msg, {time: 1500})
                    } else {
                        if (response.data.data == null) {
                            $scope.message = null;
                            layer.msg(response.data.msg, {time: 1500});
                        } else {
                            // 组织数据
                            for (var i in response.data.data.agenorder) {
                                $scope.message.push(response.data.data.agenorder[i]);
                            }
                        }
                    }
                }, function errorCallback(response) {
                    errorHandle(response);
                });
            } else {
                layer.msg("已加载完毕", {time: 500});
            }
        };
        // 进页面先加载一次数据
        $scope.loadMore();

        // 页面可视区域高度
        var winH = $(window).height();
        var scrollHandler = function () {
            // 页面高度
            var pageH = $(document.body).height();
            // 滚动条top
            var scrollT = $(window).scrollTop();
            var toend = (pageH - winH - scrollT) / winH;
            if (toend == 0) {
                $scope.loadMore();
            }
        }
        // 定义鼠标滚动事件
        $(window).scroll(scrollHandler);

        // 根据tab获取数据
        $scope.getbystatus = function (status) {
            $scope.status = status;
            // 当前页数
            $scope.currentPage = 0;
            // 加载完毕标志
            $scope.endflg = 0;
            // 防止重复加载
            $scope.busy = false;
            // 存放数据
            $scope.message = [];
            $scope.loadMore();
        }

        //流转上级或厂家
        $scope.upto = function (orderid, type) {
            $http({
                method: 'POST',
                data: {'orderid': orderid, 'type': type},
                headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                transformRequest: function (obj) {
                    var str = [];
                    for (var p in obj) {
                        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
                    }
                    return str.join("&");
                },
                url: "/index.php/Home/AgentOnlineorder/flowagenorder"
            }).then(function successCallback(response) {
                //console.log(response.data);
                layer.msg(response.data.msg, {time: 1500})
                setTimeout(function () {
                    window.location.href = "/index.php/Home/agen/orderlist"
                }, 1500)
            }, function errorCallback(response) {
                errorHandle(response);
            });
        }

        //扫溯源码
        $scope.saoma = function (id) {
//            $http({
//                method: 'POST',
//                data: {'orderid':id},
//                headers: {'Content-Type': 'application/x-www-form-urlencoded'},
//                transformRequest: function (obj) {
//                    var str = [];
//                    for (var p in obj) {
//                        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
//                    }
//                    return str.join("&");
//                },
//                url: "/index.php/Home/AgentOnlineorder/addtracing"
//            }).then(function successCallback(response) {
//                console.log(response.data);
//                layer.msg(response.data.msg,{time:1500})
//                if(response.data.code==0){
//                    setTimeout(function () {
            window.location.href = "/index.php/home/agen/saomazhuisu?id=" + id;

//                    }, 1500)
//                }
//            }, function errorCallback(response) {
//                errorHandle(response);
//            });
        }

        // 发货
        $scope.send = function (id) {
            window.location.href = "/index.php/home/agen/sendgoods?id=" + id + "&flg=2";
        }

        // 查看物流
        $scope.logistics=function (logistics,com,id) {
            var url = "https://m.kuaidi100.com/index_all.html?type="+com+"&postid="+logistics;
            $('#kdshow').attr('src',url);
            for(var x in $scope.message){
                if($scope.message[x].id == id){
                    $scope.lgsts = $scope.message[x];
                }
            }
            $scope.kdflg = 1;
        }

        // 查看物流返回
        $scope.logisticsback = function () {
            $scope.kdflg = 0;
        }

        //订单详情
        $scope.orderdetail=function (id) {
            window.location.href= "/index.php/Home/Agen/agenorderdetail?id="+id+"&flg=2"
        }
    })
</script>
</body>
</html>
